import { http } from "@/utils/http";

/** 设备配置模型定义 */
export type DeviceConfigModel = {
  id: number;
  deviceNo: string;
  configKey: string;
  configValue: string;
  remark: string;
  createdAt: string;
  updatedAt: string;
};

/** 分页获取设备配置列表 */
export const getDeviceConfigListApi = (data: IReqPagerData) => {
  return http.request<Resp<IRespPagerData<DeviceConfigModel>>>(
    "get",
    "/device-config/page-list",
    { params: data }
  );
};

/** 新增设备配置 */
export const addDeviceConfigApi = (data: Partial<DeviceConfigModel>) => {
  return http.request<Resp<null>>("post", "/device-config", { data });
};

/** 更新设备配置 */
export const updateDeviceConfigApi = (id: number, data: Partial<DeviceConfigModel>) => {
  return http.request<Resp<null>>("put", `/device-config/${id}`, { data });
};

/** 删除设备配置 */
export const deleteDeviceConfigApi = (id: number) => {
  return http.request<Resp<null>>("delete", `/device-config/${id}`);
};

/** 根据ID获取设备配置详情 */
export const getDeviceConfigByIdApi = (id: number) => {
  return http.request<Resp<{
    info: DeviceConfigModel
  }>>('get', '/device-config/getOne', {
    params: { id }
  });
};

/** 获取设备配置 */
export const getDeviceConfigApi = (params: {
  deviceNo: string;
  configKey: string;
}) => {
  return http.request<Resp<{
    configValue: any;
    updatedAt: number;
    id: number;
  }>>('get', '/device-config/getConfig', { params });
};

/** 设置设备配置 */
export const setDeviceConfigApi = (data: {
  deviceNo: string;
  configKey: string;
  configValue: any;
  copyDevices?: string[];
}) => {
  return http.request<Resp<null>>('post', '/device-config/setConfig', { data });
};
